﻿using System;
using System.Collections.Generic;
using System.Web;
using He.Web.UI;

namespace He.Web.tools
{
    /// <summary>
    /// save_title_ajax 的摘要说明
    /// </summary>
    public class save_title_ajax : AjaxHandler
    {

        public override void ProcessRequest(HttpContext context)
        {
            UI.Manage bk = new UI.Manage();
            if (!bk.IsAdminLogin())
            {
                EchoJson(0, "您还未登陆，请先登陆");
                return;
            }

            //取得事件类型
            string action = InputUtil.Get("action");

            switch (action)
            {
                //修改字表标题
                case "saveChildTitle":
                    SaveChildTitle(context);
                    break;
                //修改分类标题
                case "saveCategoryTitle":
                    SaveCategoryTitle(context);
                    break;
            }
        }

        #region 修改字表标题===================================
        private void SaveChildTitle(HttpContext context)
        {
            int channel_id;
            int id;
            if (!int.TryParse(InputUtil.Form("channel_id"), out channel_id))
            {
                return;
            }
            if (!int.TryParse(InputUtil.Form("id"), out id))
            {
                return;
            }
            string title = InputUtil.Form("title").Trim();
            if (string.IsNullOrEmpty(title))
            {
                return;
            }
            Model.channel smodel = new He.BLL.channel().GetModelByCache(channel_id);
            new BLL.article().UpdateField(id, "title='" + title + "'");
            context.Response.Write(title);
        }
        #endregion

        #region 修改分类标题===================================
        private void SaveCategoryTitle(HttpContext context)
        {
            int id;
            if (!int.TryParse(InputUtil.Form("id"), out id))
            {
                return;
            }
            string title = InputUtil.Form("title").Trim();
            if (string.IsNullOrEmpty(title))
            {
                return;
            }
            new BLL.category().UpdateField(id, "title='" + title + "'");
            context.Response.Write(title);
        }

        #endregion

        public override bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}